Clean Cursive Handwritten Notes

Page 1

Chapter 2 - Operators and Expressions

Operators are used to perform operations on variables and values.

Figure: Operator Expression Diagram

A simple arithmetic expression showing: 7 + 11 = 18, with arrows pointing to labels identifying "operand", "operator", "operand", and "result".

View full page image

Types of operators

Arithmetic operators cannot work with booleans

% operator can work on floats & doubles

Precedence of operators

The operators are applied and evaluated based on precedence. For example (÷,-) has less precedence compared to (*,/). Hence * & / are evaluated first.

In case we like to change this order, we use parenthesis

Associativity

Associativity tells the direction of execution of operators

It can either be Left to Right or Right to left

Operator Associativity Examples
Operator Associativity
* / L to R
+ - L to R
++, = R to L